﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>

<!DOCTYPE html>
<html>
@* <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.18/dist/css/layui.css" rel="stylesheet">
</head> *@
<body>
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <div class="layui-form-item">


                <div class="layui-form-item">
                    <label class="layui-form-label">测定日期</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <input type="date" id="measurementdate" class="layui-input demo-phone">
                    </div>


                    <label class="layui-form-label">羊只耳号</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <select id="earBugles">
                            <option value="">请选择</option>
                        </select>
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">身高(cm)</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <input type="text" id="sheepHeight" lay-verify="required" autocomplete="off" lay-reqtext="请输入用户名" lay-affix="clear" class="layui-input demo-phone">
                    </div>

                    <label class="layui-form-label">体长(cm)</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <input type="text" id="sheepLength" lay-verify="required" autocomplete="off" lay-reqtext="请输入用户名" lay-affix="clear" class="layui-input demo-phone">
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">胸围(cm)</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <input type="text" id="sheepChest" lay-verify="required" autocomplete="off" lay-reqtext="请输入用户名" lay-affix="clear" class="layui-input demo-phone">
                    </div>

                    <label class="layui-form-label">管围(cm)</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <input type="text" id="sheepPipe" lay-verify="required" autocomplete="off" lay-reqtext="请输入用户名" lay-affix="clear" class="layui-input demo-phone">
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">阴囊围(cm)</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <input type="text" id="sheepScrotum" lay-verify="required" autocomplete="off" lay-reqtext="请输入用户名" lay-affix="clear" class="layui-input demo-phone">
                    </div>

                    <label class="layui-form-label">背膘厚度(mm)</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <input type="text" id="sheepBackfat" lay-verify="required" autocomplete="off" lay-reqtext="请输入用户名" lay-affix="clear" class="layui-input demo-phone">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">眼肌面积(cm²)</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <input type="text" id="eyemuscleArea" lay-verify="required" autocomplete="off" lay-reqtext="请输入用户名" lay-affix="clear" class="layui-input demo-phone">
                    </div>

                    <label class="layui-form-label">眼肌宽度(cm)</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <input type="text" id="eyemuscleWidth" lay-verify="required" autocomplete="off" lay-reqtext="请输入用户名" lay-affix="clear" class="layui-input demo-phone">
                    </div>
                </div>


            </div>

            <div class="layui-form-item">
                <button type="button" class="layui-btn layui-bg-red" lay-on="test-iframe-curl" onclick="Add()">保存</button>

            </div>
        </div>
    </form>

    <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
    <script src="//unpkg.com/layui@2.9.18/dist/layui.js"></script>
    <script>
        layui.use(['table'], function () {
            var table = layui.table;
            var form = layui.form;
            var layer = layui.layer;

        });
    </script>
</body>

</html>

<script>
    var form = layui.form;
    var $ = layui.jquery;

    $(function () {
        bangsheng();
    })
    function bangsheng() {

        $.ajax({
            url: "http://localhost:5269/api/SheepArchive/SheepEarBuglesQuery",
            data: JSON.stringify({}),
            type: "post",
            async: false,
            dataType: "json",
            contentType: "application/json",
            success: res => {
                console.log(res)
                $.each(res.data, function () {
                    $("#earBugles").append(`<option value="${this.recordId}">${this.recordAuricle}</option>`);
                })
                form.render('select'); // 重新渲染下拉框

            }

        })
    }

    function Add() {

        var measurementdate = null;
        var data = {
            measurementdate: measurementdate,
            sheepNumber: $("#earBugles").val(),
            sheepHeight: $("#sheepHeight").val(),
            sheepLength: $("#sheepLength").val(),
            sheepChest: $("#sheepChest").val(),
            sheepPipe: $("#sheepPipe").val(),
            sheepScrotum: $("#sheepScrotum").val(),
            sheepBackfat: $("#sheepBackfat").val(),
            eyemuscleArea: $("#eyemuscleArea").val(),
            eyemuscleWidth: $("#eyemuscleWidth").val(),
        }

        $.ajax({
            url: "http://localhost:5269/api/SheepArchive/MeasurementBodyCreate",
            type: 'post',
            data: JSON.stringify(data),
            dataType: "json",
            contentType: "application/json",
            success: res => {
                if (res.code == 0) {
                    layer.msg('添加成功')
                    location.href = '/Breesing/Bodymeasure'
                }
                else {
                    layer.msg('保存失败')
                }
            }
        })
    }
</script>
